<script setup lang="ts">
import dayjs from 'dayjs'
import useUser from '../../composition/useUser'
import useCommont from '../../composition/useCommont'

const { getUserCommontList } = useUser()
const { commontList, deleteCommont } = useCommont()

getUserCommontList().then((res) => {
   commontList.value = res.data
})

const onClickLeft = () => history.back()
</script>

<template>
   <div>
      <van-nav-bar :title="$route.meta.title" left-text="返回" left-arrow @click-left="onClickLeft" />
      <div
         class="item mb-3 border-b-1"
         v-for="item in commontList"
         :key="item.id"
         @click="$router.push({ name: 'detail', params: { id: item.articelId } })">
         <van-swipe-cell>
            <van-cell :border="false" :title="item.content" :value="dayjs(item.createDate).fromNow()" />
            <template #right>
               <van-button square @click="deleteCommont(+item.articelId, +item.id)" type="danger" text="删除" />
            </template>
         </van-swipe-cell>
      </div>
   </div>
</template>
